<template>
  <div class="app-container home">
    <el-row :gutter="20">
      <el-col :sm="24" :lg="12" style="padding-left: 20px">
        <h1>POS分润后台管理框架</h1>
      </el-col>
    </el-row>
    <el-divider/>
    <el-row :gutter="60" class="panel-group">
      <el-col :xs="12" :sm="12" :lg="4" class="card-panel-col">
        <div class="card-panel">
          <div class="card-panel-icon-wrapper icon-people">
            <svg-icon icon-class="peoples" class-name="card-panel-icon"/>
          </div>
          <div class="card-panel-description">
            <div class="card-panel-text">
              用户数量
            </div>
            <countTo :startVal='0' :endVal='form.userCount' :duration='3000' class="card-panel-num"/>
          </div>
        </div>
      </el-col>
      <el-col :xs="12" :sm="12" :lg="4" class="card-panel-col">
        <div class="card-panel">
          <div class="card-panel-icon-wrapper icon-message">
            <svg-icon icon-class="message" class-name="card-panel-icon"/>
          </div>
          <div class="card-panel-description">
            <div class="card-panel-text">
              终端商品数量
            </div>
            <countTo :startVal='0' :endVal='form.terminalSum' :duration='3000' class="card-panel-num"/>
          </div>
        </div>
      </el-col>
      <el-col :xs="12" :sm="12" :lg="4" class="card-panel-col">
        <div class="card-panel">
          <div class="card-panel-icon-wrapper icon-money">
            <svg-icon icon-class="money" class-name="card-panel-icon"/>
          </div>
          <div class="card-panel-description">
            <div class="card-panel-text">
              兑换商品数量
            </div>
            <countTo :startVal='0' :endVal='form.exchangeSum' :duration='3000' class="card-panel-num"/>
          </div>
        </div>
      </el-col>
      <el-col :xs="12" :sm="12" :lg="4" class="card-panel-col">
        <div class="card-panel">
          <div class="card-panel-icon-wrapper icon-shopping">
            <svg-icon icon-class="shopping" class-name="card-panel-icon"/>
          </div>
          <div class="card-panel-description">
            <div class="card-panel-text">
              采购订单数量
            </div>
            <countTo :startVal='0' :endVal='form.purchaseSum' :duration='3000' class="card-panel-num"/>
          </div>
        </div>
      </el-col>
      <el-col :xs="12" :sm="12" :lg="4" class="card-panel-col">
        <div class="card-panel">
          <div class="card-panel-icon-wrapper icon-peoples">
            <svg-icon icon-class="peoples" class-name="card-panel-icon"/>
          </div>
          <div class="card-panel-description">
            <div class="card-panel-text">
              兑换订单数量
            </div>
            <countTo :startVal='0' :endVal='form.orderExchangeSum' :duration='3000' class="card-panel-num"/>
          </div>
        </div>
      </el-col>
    </el-row>
    <el-divider/>
    <el-row>
      <el-col :span="24" class="card-panel-col">
        <div id="myChart" style="height:400px"></div>
      </el-col>
    </el-row>
    <el-divider/>
    <el-row>
      <el-col :xs="12" :sm="12" :lg="8" class="card-panel-col">
        <div id="myChart1" style="height:400px;"></div>
      </el-col>
      <el-col :xs="12" :sm="12" :lg="8" class="card-panel-col">
        <div id="myChart2" style="height:400px;"></div>
      </el-col>
      <el-col :xs="12" :sm="12" :lg="8" class="card-panel-col">
        <div id="myChart3" style="height:400px;"></div>
      </el-col>
    </el-row>
    <el-divider/>
  </div>
</template>
<script>
  import {quantitySum , queryUserChart , queryOrderChart, queryOrderTerminalChart, queryOrderExchangeChart } from "@/api/homePage";
  import countTo from 'vue-count-to';

  export default {
    components: {countTo},
    data() {
      return {
        // 表单参数
        form: {
          userCount: null,
          terminalSum: null,
          exchangeSum: null,
          purchaseSum: null,
          orderExchangeSum: null,
        },
        queryUserList:{
          createTime:[],
          userSum:[],
        },
        orderList:{
          createTime:[],
          orderSum:[],
        },
        terminalList:{
          createTime:[],
          goodsNum:[],
        },
        exchangeList:{
          createTime:[],
          goodsNum:[],
        },
      }
    },
    mounted() {
      this.getList();
    },
    methods: {

      getList() {
        quantitySum().then(response => {
          this.form = response.data;
        });
        queryUserChart().then(response => {
          this.queryUserList = response.data
          this.userChart();
        });
        queryOrderChart().then(response => {
          this.orderList = response.data
          this.orderChart();
        });
        queryOrderTerminalChart().then(response => {
          console.log(response)
          this.terminalList = response.data
          this.orderTerminalChart();
        });
        queryOrderExchangeChart().then(response => {
          this.exchangeList = response.data
          this.orderExchangeChart();
        });
      },
      userChart() {
        // 基于准备好的dom，初始化echarts实例
        let myChart = this.$echarts.init(document.getElementById('myChart'))
        // 绘制图表
        myChart.setOption({
          title: {text: '用户统计'},
          legend: {
            data: ['用户增长数'],
          },
          tooltip: {
            trigger: 'axis',
          },
          xAxis: {
            data: this.queryUserList.createTime
          },
          yAxis: {},
          series: [{
            name: '用户增长数',
            type: 'bar',
            data: this.queryUserList.userSum
          }]
        });
      },
      orderChart() {
        // 基于准备好的dom，初始化echarts实例
        let myChart1 = this.$echarts.init(document.getElementById('myChart1'))
        // 绘制图表
        myChart1.setOption({
          title: {text: '订单统计'},
          tooltip: {
            trigger: 'axis'
          },
          xAxis: {
            data: this.orderList.createTime,
          },
          yAxis: {},
          series: [{
            name: '订单销量',
            type: 'line',
            smooth: true,
            stack: 'Total',
            data: this.orderList.orderSum
          }]
        });
      },
      orderTerminalChart() {
        // 基于准备好的dom，初始化echarts实例
        let myChart2 = this.$echarts.init(document.getElementById('myChart2'))
        // 绘制图表
        myChart2.setOption({
          title: {text: '采购商品统计'},
          tooltip: {
            trigger: 'axis'
          },
          xAxis: {
            data: this.terminalList.createTime
          },
          yAxis: {},
          series: [{
            name: '商品销量',
            type: 'line',
            smooth: true,
            stack: 'Total',
            data: this.terminalList.goodsNum
          }]
        });
      },
      orderExchangeChart(){

        // 基于准备好的dom，初始化echarts实例
        let myChart3 = this.$echarts.init(document.getElementById('myChart3'))
        // 绘制图表
        myChart3.setOption({
          title: {text: '兑换商品统计'},
          tooltip: {
            trigger: 'axis'
          },
          xAxis: {
            data: this.exchangeList.createTime
          },
          yAxis: {},
          series: [{
            name: '商品销量',
            type: 'line',
            smooth: true,
            stack: 'Total',
            data: this.exchangeList.goodsNum
          }]
        });
      }
    }
  }
</script>


<style lang="scss" scoped>
  .panel-group {
    margin-top: 18px;

    .card-panel-col {
      margin-bottom: 32px;
      margin-right: 50px;
    }

    .card-panel {
      height: 128px;
      cursor: pointer;
      font-size: 12px;
      position: relative;
      overflow: hidden;
      color: #666;
      background: #fff;
      box-shadow: 4px 4px 40px rgba(0, 0, 0, 0.05);
      border-color: rgba(0, 0, 0, 0.05);

      &:hover {
        .card-panel-icon-wrapper {
          color: #fff;
        }


        .icon-people {
          background: #40c9c6;
        }

        .icon-message {
          background: #36a3f7;
        }

        .icon-money {
          background: #f4516c;
        }

        .icon-shopping {
          background: #34bfa3;
        }

        .icon-peoples {
          background: rgba(191, 52, 177, 0.95);
        }
      }

      .icon-people {
        color: #40c9c6;
      }

      .icon-peoples {
        color: rgba(191, 52, 177, 0.95);
      }

      .icon-message {
        color: #36a3f7;
      }

      .icon-money {
        color: #f4516c;
      }


      .card-panel-icon-wrapper {
        float: left;
        margin: 14px 0 0 14px;
        padding: 16px;
        transition: all 0.38s ease-out;
        border-radius: 6px;
      }

      .card-panel-icon {
        float: left;
        font-size: 48px;
      }

      .card-panel-description {
        float: right;
        font-weight: bold;
        margin: 26px;
        margin-left: 0px;

        .card-panel-text {
          line-height: 18px;
          color: rgba(0, 0, 0, 0.45);
          font-size: 16px;
          margin-bottom: 12px;
        }

        .card-panel-num {
          font-size: 20px;
        }
      }
    }
  }

  @media (max-width: 550px) {
    .card-panel-description {
      display: none;
    }

    .card-panel-icon-wrapper {
      float: none !important;
      width: 120%;
      height: 120%;
      margin: 0 !important;

      .svg-icon {
        display: block;
        margin: 14px auto !important;
        float: none !important;
      }
    }
  }
</style>
